Ext.define('App.controller.carType.CarTypeViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.carTypeViewController',
	menu : Ext.widget('menu'),
	control : {
		'carTypeView carTypeSearch basesearchform' : {
			beforerender : function(form) {
				var buttons = {
					'bs/carType/saveCarType' : function(permit) {
                        var carDealerId = form.down("carDealerSingleSelect").down("[itemId=carDealerId]").getValue();
                        if(!carDealerId){
                            BaseUtil.toast("请选择车系");
                            return;
                        }
						var name = form.down("[name=name]").getValue();
						if(!name){
                            BaseUtil.toast("请填写车行");
                            return;
						}

                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('carType.CarTypeStore').reload();
                        },form.getValues());
					},
                    'bs/carType/updateCarType' : function(permit) {
                        var carDealerId = form.down("carDealerSingleSelect").down("[itemId=carDealerId]").getValue();
                        if(!carDealerId){
                            BaseUtil.toast("请选择车系");
                            return;
                        }
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写车行");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('carType.CarTypeStore').reload();
                        },form.getValues());
                    }

				};
				BaseUtil.createPermitBar(form, buttons);
			},
			render : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('carType.CarTypeStore'),Ext.getCmp('carTypeView').down('carTypeSearch form').getForm().getFieldValues());
			}
		},
		'carTypeView carTypeList':{
            itemclick:function(view, record, item, index, e, eOpts){
                var search  =  Ext.getCmp('carTypeView').down('carTypeSearch form');
                search.reset();
                search.loadRecord(record);
            },
		},
		'carTypeView carTypeSearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('carType.CarTypeStore'),Ext.getCmp('carTypeView').down('carTypeSearch form').getForm().getFieldValues());
			}
		}
	}
});